const app = getApp(); //引入自定义头部导航

var util = require('../../utils/common.js'); //引入公共JS


import { Jqwenda } from 'jqWenda_model.js';
var jqwenda = new Jqwenda();
Page({
  data: {
    showIcon: true,
    //显示返回键以及首页
    noLogin: false,
    //未登录
    lineLogin: true //已登录

  },
  onLoad: function (options) {
    //console.log(options)
    var aid = options.aid;
    var title = options.title;
    this.data.id = aid;
    this.setData({
      'aid': aid,
      'title': title
    }); //页面打开判断是否登陆过

    util.isLogin(this);

    this._onLoad();
  },
  _onLoad: function () {
    jqwenda.getAnswers(this.data.id, res => {
      console.log(res);
      this.setData({
        'Answers': res
      });
    });
  },
  //小程序未登录时点击授权登录
  bindGetUserInfo: function () {
    var that = this;
    tt.getUserInfo({
      success: function () {
        that.setData({
          noLogin: true,
          //未登录
          lineLogin: false //登录后

        });
        tt.showToast({
          //如果没有登录就显示授权弹框
          title: '登录成功！'
        }); //显示2秒隐藏加载提示

        setTimeout(function () {
          tt.hideToast();
        }, 1000);
      }
    });
  },
  formSubmit: function (e) {
    if (e.detail.value.name.length == 0) {
      tt.showToast({
        title: '内容不得为空!',
        icon: 'loading',
        duration: 1000
      });
    } else {
      var name = e.detail.value.name;
      var aid = e.detail.value.aid; //console.log(aid)

      this.data.name = name;
      this.data.aid = aid;
      jqwenda.getAnswersAdd(this.data.name, this.data.aid, data => {
        //查询出演出订单数据
        console.log(data);

        if (data == '1') {
          tt.showToast({
            title: '提交成功',
            icon: 'loading',
            duration: 1500
          });
        } else {
          tt.showToast({
            title: '半小时提交一次',
            icon: 'loading',
            duration: 1500
          });
        }
      });
    }
  },
  // 获取滚动条当前位置
  onPageScroll: function (e) {
    if (e.scrollTop > 100) {
      this.setData({
        floorstatus: true
      });
    } else {
      this.setData({
        floorstatus: false
      });
    }
  },
  //回到顶部
  goTop: function () {
    // 一键回到顶部
    util.goTop();
  },
  //分享
  onShareAppMessage: function () {
    util.sharePage();
  },
  // 拨打电话
  calling: function () {
    util.calling();
  }
});